package com.raos.example.memory.repository;

import com.raos.example.memory.entity.MyChatMessage;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 会话消息持久化层接口
 *
 * @author raos
 * @date 2025-07-12 16:45
 */
@Repository
public interface MyChatMessageRepository extends JpaRepository<MyChatMessage, String> {

    /**
     * 根据会话ID获取会话消息列表
     *
     * @param memoryId 会话ID
     * @return 会话消息列表
     */
    @Query(
            value = "SELECT * FROM ai_chat_message WHERE chatMemoryId = :memoryId ORDER BY addTime ASC",
            nativeQuery = true
    )
    List<MyChatMessage> findAllByChatMemoryId(@Param("memoryId") String memoryId);
}
